<?php

include_once 'config.php';

// we begin by initializing ncurses
$ncurse = ncurses_init();
// let ncurses know we wish to use the whole screen
$fullscreen = ncurses_newwin ( 0, 0, 0, 0); 
// draw a border around the whole thing.
ncurses_border(0,0, 0,0, 0,0, 0,0);

ncurses_attron(NCURSES_A_REVERSE);
ncurses_mvaddstr(0,1,"My first ncurses application");
ncurses_attroff(NCURSES_A_REVERSE);

// now lets create a small window
$small = ncurses_newwin(10, 30, 7, 25);
// border our small window.
ncurses_wborder($small,0,0, 0,0, 0,0, 0,0);

ncurses_refresh();// paint both windows

// move into the small window and write a string
ncurses_mvwaddstr($small, 5, 5, "   Test  String   ");
// show our handiwork and refresh our small window
ncurses_wrefresh($small);

$pressed = ncurses_wgetch($small);// wait for a user keypress

$menu = array ("one", "two", "three", "four" );
for($a = 0; $a < count ( $menu ); $a ++) {
	$out = $menu [$a];
	if ($currently_selected == intval ( $a )) {
		ncurses_wattron ( $small, NCURSES_A_REVERSE );
		ncurses_mvwaddstr ( $small, 1 + $a, 1, $out );
		ncurses_wattroff ( $small, NCURSES_A_REVERSE );
	} else {
		ncurses_mvwaddstr ( $small, 1 + $a, 1, $out );
	}
}
ncurses_wrefresh ( $small ); // otherwise we will not see


//$pressed = ncurses_getch ( $lower_main_window ); // wait for user to press key
if ($pressed == NCURSES_KEY_UP) {
	$currently_selected --;
	if ($currently_selected < 0) {
		$currently_selected = 0;
	}
} elseif ($pressed == NCURSES_KEY_DOWN) {
	$currently_selected ++;
	if ($currently_selected >= count ( $menu )) {
		$currently_selected = count ( $menu ) - 1;
	}
} elseif ($pressed == ESCAPE_KEY) {
	ncurses_end ();
	exit ();
} else {
	ncurses_mvwaddstr ( $small, 5, 5, $pressed );
}


 
/*###############
 * 
 * http://devzone.zend.com/article/1083#Heading10
 * http://cn.php.net/manual/en/function.ncurses-attron.php
 * http://alexeyrybak.com/php_ncurses_faq.html
 * http://invisible-island.net/ncurses/ncurses-intro.html
 * 
##############*/
